import { post, ResultBean } from "@/utils/request";

// ================= 后端 DTO 类型定义 =================
export interface ProcessCreateDTO {
  modelId?: string;
  modelName: string;
  processType: "plan" | "normal";
  changeProcess?: boolean;
  stepNums?: number;
  version?: number;
  tenantId?: number;
  transact?: boolean;
  uiInfo?: string;
  oldVersion?: number;
  icon?: string;
  failToRestart?: boolean;
}

export interface NodeCreateDTO {
  nodeId?: string;
  nodeKey: string;
  nodeName: string;
  viewId?: string;
  viewJson?: string;
  tip?: string;
  noticeTag?: boolean;
  noticeInitiator?: boolean;
  appId?: string;
  appVersion?: string;
  nodeType: "form" | "approval" | "task" | "auto" | "control" | "condition";
  timeOut?: number;
  task?: any;
  funcDTO?: any;
  nodeNoticeAddDTOs?: any[];
  childModelId?: string;
  childVersion?: number;
  rejectProcessConfEntity?: any;
  autoSkip?: boolean;
  nodeSkip?: boolean;
}

export interface SequenceCreateDTO {
  sequenceKey: string;
  fromNodeId: string;
  toNodeId: string;
  condition?: string; // 'yes' | 'no'
}

export interface NodeLineDTO {
  edges: SequenceCreateDTO[];
}

export interface ProcessVariableAddDTO {
  modelId?: string;
  modelName: string;
  key?: string;
  displayValue?: string;
}

export interface NodeTargetAddDTO {
  nodeKey: string;
  value: string;
  type: string;
}

export interface NodeOutputDTO {
  nodeKey: string;
  alias: string;
  expression: string;
  type: string;
  index: number;
  defaultValue: string;
}

export interface ProcessDTO {
  model: ProcessCreateDTO;
  nodes: NodeCreateDTO[];
  nodeLineDTO: NodeLineDTO;
  processVariableAddDTOs?: ProcessVariableAddDTO[];
  nodeTargetAddDTOs?: NodeTargetAddDTO[];
  nodeOutputAddDTOs?: NodeOutputDTO[];
}

// ================= API =================
export function saveProcess(data: ProcessDTO) {
  return post<ResultBean<any>>("/process/processModel/create", data);
}
